const Stack = require('./stack')

function MinStack() {
  const stack = new Stack()
  const minStack = new Stack()

  this.push = function (item) {
    stack.push(item)
    if (minStack.isEmpty() || minStack.top() > item) {
      minStack.push(item)
    } else {
      minStack.push(minStack.top())
    }
  }
  this.pop = function () {
    if (stack.isEmpty()) return false
    stack.pop()
    minStack.pop()
  }
  this.min = function () {
    return minStack.top()
  }
}

const minStack = new MinStack()

minStack.push(3) // [3]
console.log(minStack.min()) // 3
minStack.push(2) // [3,2]
console.log(minStack.min()) // 2
minStack.push(5) // [3,2,5]
console.log(minStack.min()) // 2
minStack.push(-1) // [3,2,5,-1]
console.log(minStack.min()) // -1
minStack.pop() // [3,2,5]
minStack.pop() // [3,2]
minStack.pop() // [3]
console.log(minStack.min()) // 3

// 3
// 2
// 2
// -1
// 3
